home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-08 | 18.5 KB | 648 lines | [TEXT/CWIE] |
- //
- // GrayCouncil
- // Copyright ©1996 by Trygve Isaacson. All Rights Reserved.
- //
- // This file contains the GrayCouncil PowerPlant test program's
- // application class implementation.
- //
-
- #include "MyApplication.h"
-
- #include <LGrowZone.h>
- #include <LWindow.h>
- #include <PP_Messages.h>
- #include <PP_Resources.h>
- #include <PPobClasses.h>
- #include <UDrawingState.h>
- #include <UMemoryMgr.h>
- #include <URegistrar.h>
- #include <LEditField.h>
- #include <LGroupBox.h>
- #include <UModalDialogs.h>
-
- #include "MyConstants.h"
-
- void main(void)
- {
- //
- // Initialize PowerPlant.
- //
-
- SetDebugThrow_(debugAction_Alert);
- SetDebugSignal_(debugAction_Alert);
-
- InitializeHeap(3);
-
- UQDGlobals::InitializeToolbox(&qd);
-
- new LGrowZone(20000);
-
- //
- // Initialize The Gray Council.
- //
-
- (void) InitGrayCouncilPP();
-
- //
- // Run our app.
- //
-
- MyApplication myApp;
- myApp.Run();
- }
-
- #undef Inherited
- #define Inherited LApplication
-
- MyApplication::MyApplication()
- {
- RegisterAllPPClasses();
-
- // Init the pointers & stuff used during idling.
- mProgressIndicator1 = NULL;
- mProgressIndicator2 = NULL;
- mMovingProgressOrigin = FALSE;
- mSkipNext = FALSE;
-
- this->StartRepeating(); // make LPeriodical start idling
- }
-
- MyApplication::~MyApplication()
- {
- }
-
- void MyApplication::StartUp()
- {
- //
- // Create and open our main window.
- //
-
- LWindow *theWindow;
- theWindow = LWindow::CreateWindow(kMainWindowViewID, this);
- theWindow->Show();
-
- //
- // Set up to catch button clicks in our main window.
- //
-
- for (UInt32 i = 0; i < kNumDialogs; i++)
- {
- LControl* aButton = (LControl*) theWindow->FindPaneByID(kMyCommandBase + i);
- if (aButton != NULL) // not all of our commands have a button!
- aButton->AddListener(this);
- }
- }
-
- Boolean MyApplication::ObeyCommand(CommandT inCommand, void *ioParam)
- {
- Boolean cmdHandled = TRUE;
-
- if ((inCommand >= kMyCommandBase) && (inCommand < kMyCommandBase + kNumDialogs))
- {
- // Got a menu command for one of our dialogs. Run the
- // corresponding dialog.
-
- this->PoseExampleDialog(inCommand - kMyCommandBase);
- }
- else if (inCommand == cmd_About)
- {
- // Run the about box.
-
- StDialogHandler aDlgHandler(kAboutBoxViewID, this);
- LWindow* aDialog = aDlgHandler.GetDialog();
- MessageT hitMessage;
-
- aDialog->Show();
-
- do
- {
-
- hitMessage = aDlgHandler.DoDialog();
-
- } while ((hitMessage != msg_OK) && (hitMessage != msg_Cancel));
- }
- else
- cmdHandled = Inherited::ObeyCommand(inCommand, ioParam);
-
- return cmdHandled;
- }
-
- void MyApplication::FindCommandStatus(CommandT inCommand, Boolean& outEnabled, Boolean& outUsesMark, Char16& outMark, Str255 outName)
- {
- // Enable our menu commands.
-
- if ((inCommand >= kMyCommandBase) && (inCommand < kMyCommandBase + kNumDialogs))
- outEnabled = TRUE;
- else
- Inherited::FindCommandStatus(inCommand, outEnabled, outUsesMark, outMark, outName);
- }
-
- static SInt32 MaxSInt32(SInt32 a, SInt32 b) { return (a > b) ? a : b; }
-
- void MyApplication::ListenToMessage(MessageT inMessage, void *ioParam)
- {
- if ((inMessage >= kMyCommandBase) && (inMessage < kMyCommandBase + kNumDialogs))
- {
- // Got a button click in our main window. Run the
- // corresponding dialog.
-
- this->PoseExampleDialog(inMessage - kMyCommandBase);
- }
- else switch (inMessage)
- {
- case 'ENAB':
- this->EnableDisableDialog(mCurrentDialogIndex, mCurrentDialog, *((SInt32*) ioParam) != 0);
- break;
-
- case 'SBAR':
- {
- SInt32 newScrollValue = *((SInt32*) ioParam);
- LPane* valueTextPane = mCurrentDialog->FindPaneByID('SBTX');
-
- valueTextPane->SetValue(newScrollValue);
- valueTextPane->Draw(NULL);
- }
- break;
-
- case 'LIVE':
- case 'PROP':
- {
- AGAScrollBarPP* aScrollBar;
- LStdCheckBox* liveCheckBox = (LStdCheckBox*) mCurrentDialog->FindPaneByID('LIVE');
- LStdCheckBox* propCheckBox = (LStdCheckBox*) mCurrentDialog->FindPaneByID('PROP');
- Boolean live = (liveCheckBox->GetValue() != 0);
- Boolean proportional = (propCheckBox->GetValue() != 0);
-
- ThrowIfNil_(aScrollBar = (AGAScrollBarPP*) mCurrentDialog->FindPaneByID('SBAR'));
- aScrollBar->mAGAObject->SetAttributes(AGAObject::kHorizontal, live, proportional);
- if (inMessage == 'PROP')
- aScrollBar->Refresh();
-
- ThrowIfNil_(aScrollBar = (AGAScrollBarPP*) mCurrentDialog->FindPaneByID(PaneIDT_HorizontalScrollBar));
- aScrollBar->mAGAObject->SetAttributes(AGAObject::kHorizontal, live, proportional);
- if (inMessage == 'PROP')
- aScrollBar->Refresh();
-
- ThrowIfNil_(aScrollBar = (AGAScrollBarPP*) mCurrentDialog->FindPaneByID(PaneIDT_VerticalScrollBar));
- aScrollBar->mAGAObject->SetAttributes(AGAObject::kVertical, live, proportional);
- if (inMessage == 'PROP')
- aScrollBar->Refresh();
- }
- break;
-
- case 'LVSL':
- case 'PRSL':
- {
- AGASliderPP* aSlider;
- LStdCheckBox* liveCheckBox = (LStdCheckBox*) mCurrentDialog->FindPaneByID('LVSL');
- LStdCheckBox* propCheckBox = (LStdCheckBox*) mCurrentDialog->FindPaneByID('PRSL');
- Boolean live = (liveCheckBox->GetValue() != 0);
- Boolean proportional = (propCheckBox->GetValue() != 0);
-
- aSlider = (AGASliderPP*) mCurrentDialog->FindPaneByID('VSPL');
- aSlider->mAGAObject->SetAttributes(AGAObject::kVertical, live, proportional);
- if (inMessage == 'PRSL') aSlider->Refresh();
-
- aSlider = (AGASliderPP*) mCurrentDialog->FindPaneByID('VSPR');
- aSlider->mAGAObject->SetAttributes(AGAObject::kVertical, live, proportional);
- if (inMessage == 'PRSL') aSlider->Refresh();
-
- aSlider = (AGASliderPP*) mCurrentDialog->FindPaneByID('VSRC');
- aSlider->mAGAObject->SetAttributes(AGAObject::kVertical, live, proportional);
- if (inMessage == 'PRSL') aSlider->Refresh();
-
- aSlider = (AGASliderPP*) mCurrentDialog->FindPaneByID('HSPL');
- aSlider->mAGAObject->SetAttributes(AGAObject::kHorizontal, live, proportional);
- if (inMessage == 'PRSL') aSlider->Refresh();
-
- aSlider = (AGASliderPP*) mCurrentDialog->FindPaneByID('HSPR');
- aSlider->mAGAObject->SetAttributes(AGAObject::kHorizontal, live, proportional);
- if (inMessage == 'PRSL') aSlider->Refresh();
-
- aSlider = (AGASliderPP*) mCurrentDialog->FindPaneByID('HSRC');
- aSlider->mAGAObject->SetAttributes(AGAObject::kHorizontal, live, proportional);
- if (inMessage == 'PRSL') aSlider->Refresh();
- }
- break;
-
- case 'GO_1':
- {
- // Save the pointer to the indeterminate progress indicator,
- // so we'll increment it at idle. Swap the enable states
- // of its Go and Stop buttons.
-
- this->ToggleButtons('GO_1', 'STP1');
-
- mProgressIndicator1 = (AGAProgressIndicatorPP*) mCurrentDialog->FindPaneByID('PRG1');
- }
- break;
-
- case 'GO_2':
- {
- // Save the pointer to the determinate progress indicator,
- // so we'll increment it at idle. Swap the enable states
- // of its Go and Stop buttons.
-
- this->ToggleButtons('GO_2', 'STP2');
-
- mProgressIndicator2 = (AGAProgressIndicatorPP*) mCurrentDialog->FindPaneByID('PRG2');
- }
- break;
-
- case 'STP1':
- {
- // Null the pointer to the indeterminate progress indicator,
- // so we'll ignore it at idle. Swap the enable states
- // of its Go and Stop buttons.
-
- this->ToggleButtons('STP1', 'GO_1');
-
- mProgressIndicator1 = NULL;
- }
- break;
-
- case 'STP2':
- {
- // Null the pointer to the determinate progress indicator,
- // so we'll ignore it at idle. Swap the enable states
- // of its Go and Stop buttons.
-
- this->ToggleButtons('STP2', 'GO_2');
-
- mProgressIndicator2 = NULL;
- }
- break;
-
- case 'SETV':
- {
- // The "Set Values" button in the progress dialog was hit.
- // Poke the determinate progress indicator with the current
- // values that have been entered in the dialog.
-
- LEditField* aNumberText;
- LStdCheckBox* originCheckBox = (LStdCheckBox*) mCurrentDialog->FindPaneByID('CORG');
- SInt32 newMin;
- SInt32 newMax;
- SInt32 newValue;
- SInt32 newOrigin;
-
- AGAProgressIndicatorPP* indicator = (AGAProgressIndicatorPP*) mCurrentDialog->FindPaneByID('PRG2');
-
- aNumberText = (LEditField*) mCurrentDialog->FindPaneByID('NMIN');
- newMin = aNumberText->GetValue();
-
- aNumberText = (LEditField*) mCurrentDialog->FindPaneByID('NMAX');
- newMax = aNumberText->GetValue();
-
- indicator->mAGAObject->SetRange(newMin, newMax, AGAObject::kDontRedraw);
-
- aNumberText = (LEditField*) mCurrentDialog->FindPaneByID('NVAL');
- newValue = aNumberText->GetValue();
- indicator->mAGAObject->SetValue(newValue, AGAObject::kDontRedraw);
-
- if (originCheckBox->GetValue() == 0)
- newOrigin = newMin;
- else
- {
- aNumberText = (LEditField*) mCurrentDialog->FindPaneByID('NORG');
- newOrigin = MaxSInt32(newMin, aNumberText->GetValue());
- }
-
- indicator->mAGAObject->SetOriginValue(newOrigin, AGAObject::kDontRedraw);
-
- indicator->Refresh();
- }
- break;
-
- case 'CORG':
- {
- // The progress dialog's "Moving Origin" checkbox was hit.
- // Enable or disable the edit text and little arrows, and
- // set our flag that we'll check at idle.
-
- LStdCheckBox* aCheckBox = (LStdCheckBox*) mCurrentDialog->FindPaneByID('CORG');
- Boolean enabled = (aCheckBox->GetValue() != 0);
-
- this->EnableDisablePane('NORG', enabled);
- this->EnableDisablePane('AORG', enabled);
- this->EnableDisablePane('TORG', enabled);
-
- mMovingProgressOrigin = enabled;
- }
- break;
-
- }
- }
-
- void MyApplication::ToggleButtons(OSType buttonToDisable, OSType buttonToEnable)
- {
- mCurrentDialog->FindPaneByID(buttonToDisable)->Disable();
- mCurrentDialog->FindPaneByID(buttonToEnable)->Enable();
- }
-
- void MyApplication::EnableDisablePane(OSType paneID, Boolean enable)
- {
- if (enable)
- mCurrentDialog->FindPaneByID(paneID)->Enable();
- else
- mCurrentDialog->FindPaneByID(paneID)->Disable();
- }
-
- void MyApplication::SpendTime(const EventRecord &inMacEvent)
- {
- // If we have a pointer to the indeterminate progress indicator,
- // it's running, so crank it once.
- if (mProgressIndicator1 != NULL)
- {
- mProgressIndicator1->FocusDraw();
- mProgressIndicator1->mAGAObject->Animate();
- }
-
- // If we have a pointer to the determinate progress indicator,
- // it's running, so increment its value.
- if (mProgressIndicator2 != NULL)
- {
- mProgressIndicator2->FocusDraw();
- mProgressIndicator2->mAGAObject->Increment(1, AGAObject::kRedraw);
-
- // Increment the origin every other time, if it's moving.
- if (mMovingProgressOrigin && ! mSkipNext)
- mProgressIndicator2->mAGAObject->SetOriginValue(1 + mProgressIndicator2->mAGAObject->GetOriginValue(), AGAObject::kRedraw);
-
- mSkipNext = ! mSkipNext; // make moving origin go slower than value
- }
- }
-
- void MyApplication::PoseExampleDialog(UInt32 dialogIndex)
- {
- // Run one of our test dialogs.
-
- StDialogHandler aDlgHandler(kMyViewBase + dialogIndex, this);
- LWindow* aDialog = aDlgHandler.GetDialog();
- MessageT hitMessage;
-
- mCurrentDialog = aDialog;
- mCurrentDialogIndex = dialogIndex;
-
- this->SetupExampleDialog(dialogIndex, aDialog);
-
- aDialog->Show();
-
- do
- {
-
- hitMessage = aDlgHandler.DoDialog();
-
- } while ((hitMessage != msg_OK) && (hitMessage != msg_Cancel));
-
- this->CleanupExampleDialog(dialogIndex, aDialog);
- }
-
- void MyApplication::SetupExampleDialog(UInt32 dialogIndex, LWindow* itsWindow)
- {
- // Set up one of our test dialogs, just prior to showing it.
-
- LPane* aPane;
- LControl* aBroadcaster = (LControl*) itsWindow->FindPaneByID('ENAB');
- if (aBroadcaster != NULL) // not all of our commands have this checkbox!
- aBroadcaster->AddListener(this);
-
- switch (dialogIndex)
- {
- case kPushButtonDlgIndex:
-
- aPane = itsWindow->FindPaneByID('DFLT');
- ((AGAPushButtonPP*) aPane)->mAGAObject->SetDefault(AGAObject::kIsDefault, AGAObject::kFrameOutside);
-
- break;
-
- case kCheckBoxDlgIndex:
-
- aPane = itsWindow->FindPaneByID('CBX3');
- ((LStdCheckBox*) aPane)->SetValue(AGACheckBox::kCheckBoxMixed);
-
- break;
-
- case kRadioButtonDlgIndex:
-
- aPane = itsWindow->FindPaneByID('BTN3');
- ((LStdRadioButton*) aPane)->SetValue(AGARadioButton::kRadioButtonMixed);
-
- break;
-
- case kScrollBarDlgIndex:
-
- ((LControl*) itsWindow->FindPaneByID('LIVE'))->AddListener(this);
- ((LControl*) itsWindow->FindPaneByID('PROP'))->AddListener(this);
-
- aPane = itsWindow->FindPaneByID('SBAR');
- ((LControl*) aPane)->AddListener(this);
- ((AGAScrollBarPP*) aPane)->mAGAObject->SetPageSize(25, AGAObject::kDontRedraw);
- ((AGAScrollBarPP*) aPane)->mAGAObject->SetStepSizes(1, 25);
-
- break;
-
- case kSliderDlgIndex:
- {
- AGASliderPP* aSlider;
-
- ThrowIfNil_(aSlider = (AGASliderPP*) itsWindow->FindPaneByID('VSPL'));
- aSlider->mAGAObject->SetPageSize(1, AGAObject::kDontRedraw);
-
- ThrowIfNil_(aSlider = (AGASliderPP*) itsWindow->FindPaneByID('VSRC'));
- aSlider->mAGAObject->SetPageSize(20, AGAObject::kDontRedraw);
-
- ThrowIfNil_(aSlider = (AGASliderPP*) itsWindow->FindPaneByID('VSPR'));
- aSlider->mAGAObject->SetJustification(teFlushRight);
- aSlider->mAGAObject->SetPageSize(1, AGAObject::kDontRedraw);
-
- ThrowIfNil_(aSlider = (AGASliderPP*) itsWindow->FindPaneByID('HSPL'));
- aSlider->mAGAObject->SetPageSize(1, AGAObject::kDontRedraw);
-
- ThrowIfNil_(aSlider = (AGASliderPP*) itsWindow->FindPaneByID('HSRC'));
- aSlider->mAGAObject->SetPageSize(20, AGAObject::kDontRedraw);
-
- ThrowIfNil_(aSlider = (AGASliderPP*) itsWindow->FindPaneByID('HSPR'));
- aSlider->mAGAObject->SetJustification(teFlushRight);
- aSlider->mAGAObject->SetPageSize(1, AGAObject::kDontRedraw);
- aSlider->SetMaxValue(32);
-
- aBroadcaster = (LControl*) itsWindow->FindPaneByID('LVSL');
- aBroadcaster->AddListener(this);
-
- aBroadcaster = (LControl*) itsWindow->FindPaneByID('PRSL');
- aBroadcaster->AddListener(this);
- }
- break;
-
- case kProgressDlgIndex:
- {
- ((LControl*) itsWindow->FindPaneByID('GO_1'))->AddListener(this);
- ((LControl*) itsWindow->FindPaneByID('GO_2'))->AddListener(this);
- ((LControl*) itsWindow->FindPaneByID('STP1'))->AddListener(this);
- ((LControl*) itsWindow->FindPaneByID('STP2'))->AddListener(this);
- ((LControl*) itsWindow->FindPaneByID('SETV'))->AddListener(this);
- ((LControl*) itsWindow->FindPaneByID('CORG'))->AddListener(this);
- }
- break;
-
- case kFolderTabsDlgIndex:
-
- aBroadcaster = (LControl*) itsWindow->FindPaneByID('TPO1');
- aBroadcaster->AddListener(this);
-
- aBroadcaster = (LControl*) itsWindow->FindPaneByID('TPO2');
- aBroadcaster->AddListener(this);
-
- aBroadcaster = (LControl*) itsWindow->FindPaneByID('TPO3');
- aBroadcaster->AddListener(this);
-
- break;
-
- }
- }
-
- void MyApplication::CleanupExampleDialog(UInt32 dialogIndex, LWindow* itsWindow)
- {
- // Clean up one of our dialogs that is being closed.
-
- switch (dialogIndex)
- {
- case kProgressDlgIndex:
- {
- // Null the pointers so we don't go haywire at next idle !
-
- mProgressIndicator1 = NULL;
- mProgressIndicator2 = NULL;
- mMovingProgressOrigin = FALSE;
- mSkipNext = FALSE;
- }
- break;
- }
- }
-
- static void EnablePane(LPane* aPane, Boolean enable)
- {
- ThrowIfNil_(aPane);
-
- if (enable)
- aPane->Enable();
- else
- aPane->Disable();
- }
-
- void MyApplication::EnableDisableDialog(UInt32 dialogIndex, LWindow* itsWindow, Boolean enable)
- {
- // There is an 'ENAB' check box in many of our dialogs,
- // that enables/disables bunches o' items in the dialogs.
-
- LPane* aPane;
-
- switch (dialogIndex)
- {
- case kPushButtonDlgIndex:
-
- EnablePane(itsWindow->FindPaneByID('NORM'), enable);
- EnablePane(itsWindow->FindPaneByID('DFLT'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN1'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN2'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN3'), enable);
-
- break;
-
- case kCheckBoxDlgIndex:
-
- EnablePane(itsWindow->FindPaneByID('ICN1'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN2'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN3'), enable);
- EnablePane(itsWindow->FindPaneByID('CBX1'), enable);
- EnablePane(itsWindow->FindPaneByID('CBX2'), enable);
- EnablePane(itsWindow->FindPaneByID('CBX3'), enable);
-
- break;
-
- case kRadioButtonDlgIndex:
-
- EnablePane(itsWindow->FindPaneByID('BTN1'), enable);
- EnablePane(itsWindow->FindPaneByID('BTN2'), enable);
- EnablePane(itsWindow->FindPaneByID('BTN3'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN1'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN2'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN3'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN4'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN5'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN6'), enable);
- EnablePane(itsWindow->FindPaneByID('ICN7'), enable);
-
- break;
-
- case kSliderDlgIndex:
-
- EnablePane(itsWindow->FindPaneByID('VSPL'), enable);
- EnablePane(itsWindow->FindPaneByID('VSRC'), enable);
- EnablePane(itsWindow->FindPaneByID('VSPR'), enable);
- EnablePane(itsWindow->FindPaneByID('HSPL'), enable);
- EnablePane(itsWindow->FindPaneByID('HSRC'), enable);
- EnablePane(itsWindow->FindPaneByID('HSPR'), enable);
-
- break;
-
- case kScrollBarDlgIndex:
-
- EnablePane(itsWindow->FindPaneByID('SBAR'), enable);
- EnablePane(itsWindow->FindPaneByID(PaneIDT_HorizontalScrollBar), enable);
- EnablePane(itsWindow->FindPaneByID(PaneIDT_VerticalScrollBar), enable);
-
- break;
-
- case kPopupMenuDlgIndex:
-
- EnablePane(itsWindow->FindPaneByID('POP1'), enable);
- EnablePane(itsWindow->FindPaneByID('POP2'), enable);
- EnablePane(itsWindow->FindPaneByID('POP3'), enable);
-
- break;
-
- case kEditTextDlgIndex:
-
- EnablePane(itsWindow->FindPaneByID('EDT1'), enable);
- itsWindow->FindPaneByID('EDT1')->Refresh(); // std enable/disable does not let attachments redraw!!! ick!
-
- break;
-
- case kGroupBoxDlgIndex:
-
- EnablePane(itsWindow->FindPaneByID('GRP1'), enable);
- EnablePane(itsWindow->FindPaneByID('GR1A'), enable);
- EnablePane(itsWindow->FindPaneByID('R1A1'), enable);
- EnablePane(itsWindow->FindPaneByID('R1A2'), enable);
- EnablePane(itsWindow->FindPaneByID('GR1B'), enable);
- EnablePane(itsWindow->FindPaneByID('R1B1'), enable);
- EnablePane(itsWindow->FindPaneByID('R1B2'), enable);
-
- EnablePane(itsWindow->FindPaneByID('GRP2'), enable);
- EnablePane(itsWindow->FindPaneByID('GR2A'), enable);
- EnablePane(itsWindow->FindPaneByID('R2A1'), enable);
- EnablePane(itsWindow->FindPaneByID('R2A2'), enable);
- EnablePane(itsWindow->FindPaneByID('GR2B'), enable);
- EnablePane(itsWindow->FindPaneByID('R2B1'), enable);
- EnablePane(itsWindow->FindPaneByID('R2B2'), enable);
-
- EnablePane(itsWindow->FindPaneByID('GRP3'), enable);
- EnablePane(itsWindow->FindPaneByID('GR3A'), enable);
- EnablePane(itsWindow->FindPaneByID('R3A1'), enable);
- EnablePane(itsWindow->FindPaneByID('R3A2'), enable);
- EnablePane(itsWindow->FindPaneByID('GR3B'), enable);
- EnablePane(itsWindow->FindPaneByID('R3B1'), enable);
- EnablePane(itsWindow->FindPaneByID('R3B2'), enable);
-
- EnablePane(itsWindow->FindPaneByID('CBX1'), enable);
- EnablePane(itsWindow->FindPaneByID('CBX2'), enable);
- EnablePane(itsWindow->FindPaneByID('CBX3'), enable);
-
- break;
-
- }
- }
-
-